Interactive copying to the text fileΒΆ

import sys
from os import path

script, from_file, to_file = sys.argv

print("Reading from the file {}...".format(from_file))
f_from = open(from_file, "r")
from_file_text = f_from.read()
f_from.close()

# debug
# print("File Content: {}".format(from_file_text))

is_to_file_exists = path.exists(to_file)

if is_to_file_exists:
    print("The output file {} is already exists...".format(to_file))
    try:
        if input("Are you sure in copying into the file? (Y/n)> ").lower().startswith('n'):
            sys.exit(1)
    except KeyboardInterrupt:
        sys.exit(1)

print("\nCopying to the file {}...".format(to_file))
f_to = open(to_file, "w")
f_to.write(from_file_text)
f_to.close()

print("Finished")

# debug
f_to = open(to_file, "r")
to_file_text = f_to.read()
print("New File Content: {}".format(to_file_text))
f_to.close()